#ifndef CONNECTION_H
#define CONNECTION_H

#include <chrono>
#include <pqxx/pqxx>
/*
封装连接信息
*/

struct Connection {
  std::chrono::time_point<std::chrono::steady_clock>
      aliveTime;  //从何时起进入队列

  //刷新进入队列时间
  void refreshAliveTime() { aliveTime = std::chrono::steady_clock::now(); }
  //获取连接从进入队列到现在多长时间
  size_t getAliveTime() const {
    return std::chrono::duration_cast<std::chrono::milliseconds>(
               std::chrono::steady_clock::now() - aliveTime)
        .count();
  }
  pqxx::connection& getConn() { return conn; }
  Connection(const std::string& connect_url) : conn(connect_url) {}

 private:
  pqxx::connection conn;
};
#endif